﻿using System;
using ch10.binary.type;

namespace ch10.instance
{
    using WasmVal = Object;
    using MemType = Limits;

    public interface IModule
    {
        object GetMember(string name);
        (WasmVal[], Exception) InvokeFunc(string name, params WasmVal[] args);
        (WasmVal, Exception) GetGlobalVal(string name);
        Exception SetGlobalVal(string name, WasmVal val);
    }

    public interface IFunction
    {
        FuncType Type();
        (WasmVal[], Exception) Call(params WasmVal[] args);
    }

    public interface ITable
    {
        TableType Type();
        uint Size();
        void Grow(uint n);
        IFunction GetElem(uint idx);
        void SetElem(uint idx, IFunction elem);
    }

    public interface IMemory
    {
        MemType Type();
        uint Size(); // page count
        uint Grow(uint n);
        void Read(ulong offset, byte[] buf);
        void Write(ulong offset, byte[] buf);
    }

    public interface IGlobal
    {
        GlobalType Type();
        ulong GetAsU64();
        void SetAsU64(ulong val);
        WasmVal Get();
        void Set(WasmVal val);
    }
}